import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomePage());
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("dialog"),
      ),
      body: Column(children: <Widget>[
        RaisedButton(
          onPressed: () => showSelectDialog(context),
          child: Text("选择对话框"),
        ),
        RaisedButton(
          onPressed: () {
            showRemoveTipDialog(context);
          },
          child: Text("删除对话框"),
        ),
      ]),
    );
  }

  Future showRemoveTipDialog(BuildContext context) {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("提示"),
            content: SingleChildScrollView(
              child: ListBody(
                children: <Widget>[
                  Text("是否删除"),
                  Text("删除后不可逆转"),
                ],
              ),
            ),
            actions: <Widget>[
              FlatButton(
                child: Text("确定"),
                onPressed: () {
                  print("点击确定");
                  Navigator.pop(context);
                },
              ),
              FlatButton(
                child: Text("取消"),
                onPressed: () {
                  print("点击取消");
                  Navigator.pop(context);
                },
              ),
            ],
          );
        });
  }
}

Future showSelectDialog(BuildContext context) {
  return showDialog(
      context: context,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: Text("选择对话框"),
          children: <Widget>[
            SimpleDialogOption(
              child: Text("选项1"),
              onPressed: () => print("选项1"),
            ),
            SimpleDialogOption(
              child: Text("选项2"),
              onPressed: () => print("选项2"),
            )
          ],
        );
      });
}
